<?php /* Smarty version 2.6.16, created on 2008-07-03 16:25:22
         compiled from admin/tabs/access.tmpl */ ?>

<link rel="stylesheet" href="<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/jquery.treeview.css" />

<style type="text/css">
	  	#gray.treeview li { background: url(<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/images/gray/tv-item.gif) 0 0 no-repeat; }
	  	#gray.treeview .collapsable { background-image: url(<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/images/gray/tv-collapsable.gif); }
	  	#gray.treeview .expandable { background-image: url(<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/images/gray/tv-expandable.gif); }
	  	#gray.treeview .last { background-image: url(<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/images/gray/tv-item-last.gif); }
	  	#gray.treeview .lastCollapsable { background-image: url(<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/images/gray/tv-collapsable-last.gif); }
	  	#gray.treeview .lastExpandable { background-image: url(<?php echo $this->_tpl_vars['BASE_URL']; ?>
/a/css/admin/images/gray/tv-expandable-last.gif); }
</style>

<script language="JavaScript">
<!--
	var isChecked = "";
	function viewCheckTreeRec(obj) {
		if ( obj.is('li') ) obj.children().find('input').filter(':first').attr("checked", isChecked ? "checked" : "");
		if ( obj.attr('id') == 'gray' ) return;
		viewCheckTreeRec($(obj).parent());
	}
/*	function viewCheckTree(obj, id ) {
		isChecked = $(obj).attr("checked") ? true : false;
		user_function ( id, isChecked );
		if ( isChecked ) {
			if ( $(obj).parent().is('span') ) 
				$(obj).parent().parent().children().find('input').attr("checked", "checked");
			viewCheckTreeRec( $(obj).parent() );
		}
	}*/

	function viewCheckTree(obj, id ) {
		isChecked = $(obj).attr("checked") ? true : false;
		user_function ( id, isChecked );
		if ( isChecked ) {
			if ( $(obj).parent().is('span') ) 
				$(obj).parent().parent().children().find('input').attr("checked", "checked");
			viewCheckTreeRec( $(obj).parent() );
		} else if ( $(obj).parent().is('span') ) 
			$(obj).parent().parent().children().find('input').attr("checked", "");
	}

	function uncheckAll() {
		$("#gray").children().find('input').attr("checked", "");
	}
	function checkAll() {
		$("#gray").children().find('input').attr("checked", "checked");
	}

	function create_branch ( hash ) {
		var line = '';
		var checked = '';

		if (hash['checked'] == 1) 
			checked = 'checked';		
		
		if ( hash['children'] && typeof hash['children'] == 'object' && hash['children'] instanceof Array ) {
			line += '<li><span><input id="tree_checkbox_'+ hash['id'] +'" type="checkbox" onClick="viewCheckTree(this, '+ hash['id'] +');" '+checked+'>'+ hash['info'][0] +'</span><ul style="display:none;">';
			for (var i = 0; i < hash['children'].length; i++ ) line += create_branch ( hash['children'][i] );
			line += '</li></ul>';
		} else if ( hash && typeof hash == 'object') {
			line += '<li><input id="tree_checkbox_'+ hash['id'] +'" type="checkbox" onClick="viewCheckTree(this,'+ hash['id'] +');" '+checked+'>'+ hash['info'][0] +'</li>';
		}
		/* for test  */
//		else alert('error list: '+ hash );
		return line;
	}

	function create_tree ( hash ) {
		var line = '<ul id="gray">';
		line += create_branch ( hash );
		line += '</ul>';
		return line;
	}

	function user_function ( id, type ) {
//		if ( type ) alert('select '+ id );
//		else alert('uNselect '+ id );
	}

	function get_all_view_check () {
		var out = [];
		
		$("#gray").children().find('input').each( 
			function() { 
				if ( $(this).is('input') && $(this).attr("checked") ) 
					out.push($(this).attr("id").replace( /tree_checkbox_/,'')); 
			}
		);
//		alert (out);	  

		var form = document.getElementById('access_form');
		form.save_rules.value = 1;
		form.user_name.value  = form.user[form.user.selectedIndex].text;
		form.user_rules.value  = out;

		form.action = '/admin/system/access/' + form.user[form.user.selectedIndex].text;

	  	form.submit();

	}
//-->
</script>

<script language="JavaScript">
<!--
	var data3 = <?php echo $this->_tpl_vars['json']; ?>
;

	/*var data3 = {
		id       : 0,
		info     : ["Доступ к управлению"],//data2.columns,
		children : data2.items,
		checked	 : <?php echo $this->_tpl_vars['site_access']; ?>

	};*/
//-->
</script>
<script language="JavaScript">
	function changeUserAccess(x){
		document.location = '/admin/system/access/' + x[x.selectedIndex].text;
	}
</script>

<div id="main">
	<div id="treecontrol">
		<a href="#">Collapse All</a>
		<a href="#">Expand All</a>
		<a href="#">Toggle All</a>
	</div>
	<div>
		<a href="#" onClick="uncheckAll();">unSelect All</a>
		<a href="#" onClick="checkAll();">Select All</a>
		<a href="#" onClick="get_all_view_check();">Save</a>
	</div>

	<form action="" method="post" id="access_form" >
	<input type="hidden" name="save_rules" value="" />
	<input type="hidden" name="user_name" value="" />
	<input type="hidden" name="user_rules" value="" />
	<select name="user" onChange="changeUserAccess(this);">
<?php $_from = $this->_tpl_vars['users']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }$this->_foreach['users'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['users']['total'] > 0):
    foreach ($_from as $this->_tpl_vars['user']):
        $this->_foreach['users']['iteration']++;
?>		<option value="<?php echo $this->_tpl_vars['user']->id; ?>
"<?php if ($this->_tpl_vars['user']->login == $this->_tpl_vars['user_selected']): ?> selected<?php endif; ?>><?php echo $this->_tpl_vars['user']->login; ?>
</option><?php endforeach; endif; unset($_from); ?>
	</select>
	</form>
	<script language="JavaScript">
	<!--
		document.write(create_tree ( data3.items[0] ));
	//-->
	</script>
</div>